<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<body>
    <div id="father">
        <h1>标题</h1>
        <p id = "p1">1</p>
        <p class="p2">2</p>
    </div>

</body>

<script>
    // 删除dom对象

    // 1.获取要删除的节点
    let delTarget = document.getElementById("p1");
    // 2.获取该节点的父元素
    let father = delTarget.parentElement;
    // 3.删除
    father.removeChild(delTarget);

    //删除是动态的过程，删除多个节点的时候，children是时刻变化的，下面这样删除会报错
    //Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'.
    father.removeChild(father.children[0]);
    father.removeChild(father.children[1]);

</script>
</html>